/**
 * 
 */
package com.tomagency.cyberlab.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.tomagency.cyberlab.client.RpcServiceProvider;
import com.tomagency.cyberlab.client.ScannerApp;

import de.gammadata.gwt.modelle.ResultObject;

/**
 * @author gfr
 *
 */
public class ScannerAppViewImpl extends Composite implements ScannerAppView {
	


	/**
	 * Because this class has a default constructor, it can
	 * be used as a binder template. In other words, it can be used in other
	 * *.ui.xml files as follows:
	 * <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
	 *   xmlns:g="urn:import:**user's package**">
	 *  <g:**UserClassName**>Hello!</g:**UserClassName>
	 * </ui:UiBinder>
	 * Note that depending on the widget that is used, it may be necessary to
	 * implement HasHTML instead of HasText.
	 */
	
	@UiTemplate("ScannerAppView.ui.xml")
	interface ScannerAppViewUiBinder extends UiBinder<Widget,ScannerAppViewImpl>{}
	private static ScannerAppViewUiBinder uiBinder = GWT.create(ScannerAppViewUiBinder.class);


//	public ScannerAppViewImpl() {
//		initWidget(uiBinder.createAndBindUi(this));
//	}
//	

	private Presenter presenter;


	@UiField
	Button statusbutton;
	@UiField
	Button scanbutton;
	@UiField
	Button startbutton;
	@UiField
	Button stopbutton;
	@UiField
	Label message;
	
	public ScannerAppViewImpl(){
		initWidget(uiBinder.createAndBindUi(this));
	}

	public ScannerAppViewImpl(String buttonLabel) {
		initWidget(uiBinder.createAndBindUi(this));

		// Can access @UiField after calling createAndBindUi
		statusbutton.setText(buttonLabel);
		scanbutton.setText("Rescan");
		startbutton.setText("Start");
		stopbutton.setText("Stop");
	}
	
	public void init(){
		message.setText("");
		statusbutton.setText("Scan Status");
		scanbutton.setText("Rescan");
		startbutton.setText("Start");
		stopbutton.setText("Stop");
	}
	


	@UiHandler("statusbutton")
	void onClickStatus(ClickEvent e) {
		presenter.onStatusClicked();
	}

	
	@UiHandler("scanbutton")
	void onClickScan(ClickEvent e) {
		presenter.onRescanClicked();

	}
	
	@UiHandler("startbutton")
	void onClickStart(ClickEvent e) {
		presenter.onStartClicked();
	}
	@UiHandler("stopbutton")
	void onClickStop(ClickEvent e) {
		presenter.onStopClicked();
	}

	

	/* (non-Javadoc)
	 * @see com.tomagency.cyberlab.client.ui.ScannerAppView#setMessage(java.lang.String)
	 */
	@Override
	public void setMessage(String message) {
		this.message.setText(message);

	}

	/**
	 * @return the presenter
	 */
	public Presenter getPresenter() {
		return presenter;
	}

	/**
	 * @param presenter the presenter to set
	 */
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}

}
